import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import FuncAnimation

matplotlib.rcParams["axes.unicode_minus"] = False
fig, ax = plt.subplots()
xdata, ydata = [], []
ln, = ax.plot([], [], 'r-', animated=False)


def init():
    # ax.set_xlim(0, 2 * np.pi)
    # ax.set_ylim(-1, 1)
    return ln,


def update(frame):
    xdata.append(frame)
    # ydata.append(np.cos(frame))
    ydata.append(frame)
    ax.set_xlim(0, frame)
    ax.set_ylim(-1, 1)
    ln.set_data(xdata, ydata)
    return ln,


# ani = FuncAnimation(fig, update, frames=np.linspace(0, 2 * np.pi, 128),
#                     init_func=init, interval=0.2, blit=False)
ani = FuncAnimation(fig, update, frames=np.random.rand(128),
                    init_func=init, interval=200, blit=True)
plt.show()

if __name__ == '__main__':
    # rand = np.random.rand(128)
    # print(rand)
    # print(rand.shape)
    pass
